const Client = require("../src/net/Client")

let HOST = '127.0.0.1';
let PORT = 6969;

var client = new Client();

client.connect(PORT, HOST, function() {

    console.log('CONNECTED TO: ' + HOST + ':' + PORT);
    // 建立连接后立即向服务器发送数据，服务器将收到这些数据
    client.send({
        cmd : "hello" ,
        data : 'I am Chuck Norris!'
    });
    client.send({
        "cmd" : 'test',
        "data" : Buffer.from("huang谦", 'utf-8')
    });

    setTimeout(function () {
        client.destroy();
    }, 3000)

});



// 为客户端添加“data”事件处理函数
// data是服务器发回的数据
client.on('data', function(data) {
    console.log('DATA: ' + data);
});



// 为客户端添加“close”事件处理函数
client.on('close', function() {
    console.log('Connection closed');
});

